package com.haotunet.app.goldtreasure.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.haotunet.app.goldtreasure.R;
import com.haotunet.app.goldtreasure.model.RegularProfit;
import com.haotunet.app.goldtreasure.views.TipPopupView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class MyRegularAdapter extends HolderAdapter<RegularProfit, MyRegularAdapter.ViewHolder> {

    public MyRegularAdapter(Context context, List<RegularProfit> list) {
        super(context, list);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, RegularProfit t, int position) {
        return inflate(R.layout.item_my_regular);
    }

    @Override
    public ViewHolder buildHolder(View convertView, RegularProfit t, int position) {
        ViewHolder holder = new ViewHolder(convertView);
        return holder;
    }

    @Override
    public void bindViewDatas(View convertView, ViewHolder holder, final RegularProfit regularProfit, int position) {
        holder.txtRegularProductName.setText(regularProfit.getCategoryName());
        final String tips = regularProfit.getTips();
        if (TextUtils.isEmpty(tips)) {
            holder.ivTip.setVisibility(View.GONE);
        } else {
            holder.ivTip.setVisibility(View.VISIBLE);
        }
        if (!TextUtils.isEmpty(regularProfit.getRemark())) {
            holder.remarkTxt.setText(regularProfit.getRemark());
        }
        if (!TextUtils.isEmpty(regularProfit.getExperienceGold())) {
            if (Double.parseDouble(regularProfit.getExperienceGold()) != 0) {
                holder.experienceGold.setText("+" + regularProfit.getExperienceGold());
            }
        }
        holder.regularGoldGrams.setText(regularProfit.getQuantity());
        holder.goldUnit.setText(regularProfit.getQuantityUnit());
        holder.productRate.setText(regularProfit.getRate());
        holder.rateUnit.setText(regularProfit.getRateDesc());
        holder.productProfit.setText(regularProfit.getProfit());
        holder.profitUint.setText(regularProfit.getProfitDesc());
        holder.txtEndTime.setText("到期日 : " + regularProfit.getEndTime());
        holder.ivTip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new TipPopupView(context, null, tips, R.style.MyDialog).show();
            }
        });
    }

    static class ViewHolder {
        @InjectView(R.id.txt_regular_product_name)
        TextView txtRegularProductName;
        @InjectView(R.id.iv_tip)
        ImageView ivTip;
        @InjectView(R.id.remark_txt)
        TextView remarkTxt;
        @InjectView(R.id.regular_gold_grams)
        TextView regularGoldGrams;
        @InjectView(R.id.experience_gold)
        TextView experienceGold;
        @InjectView(R.id.gold_unit)
        TextView goldUnit;
        @InjectView(R.id.product_rate)
        TextView productRate;
        @InjectView(R.id.rate_unit)
        TextView rateUnit;
        @InjectView(R.id.product_profit)
        TextView productProfit;
        @InjectView(R.id.profit_uint)
        TextView profitUint;
        @InjectView(R.id.txt_end_time)
        TextView txtEndTime;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
